﻿#region header

//  ***************************************************************************
// *                                LICENSE
//  ***************************************************************************
//  * "Haplous" .NET Simple 2D Game Framework
//  * 
//  * Copyright © Jonathan Evans 2014-2014
//  * 
//  * This program is free software; you can redistribute it and/or
//  * modify it under the terms of the GNU General Public License
//  * as published by the Free Software Foundation; either version 2
//  * of the License, or (at your option) any later version.
//  * 
//  * This program is distributed in the hope that it will be useful,
//  * but WITHOUT ANY WARRANTY; without even the implied warranty of
//  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  * GNU General Public License for more details.
//  * 
//  * You should have received a copy of the GNU General Public License
//  * along with this program; if not, write to the Free Software
//  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//  * 
//  ***************************************************************************
//  * 
//  * Contact: opencollar@googlemail.com
//  * 
//  * Website: http://haplous.codeplex.com/
//  *
//  * NuGet:   http://www.nuget.org/packages/haplous/
//  *
//  * File:    Haplous/Haplous/SizeInt32.cs
//  *
//  ***************************************************************************

#endregion

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

using Haplous.Core;
using Haplous.Correctness;

using JetBrains.Annotations;

namespace Haplous
{
    /// <summary>
    ///     An extended implementation of <see cref="Size{T}" /> for <see cref="int" /> values. This class cannot be
    ///     inherited.
    /// </summary>
    [DebuggerDisplay("SizeInt32: {Width},{Height}")]
    public sealed class SizeInt32 : Size<int>, IProperty<SizeInt32>
    {
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        public SizeInt32()
        {}

        /// <summary>
        ///     Initializes a new instance of the <see cref="T:System.Object" /> class.
        /// </summary>
        /// <param name="width">The width, measured in pixels.</param>
        /// <param name="height">The height, measured in pixels.</param>
        public SizeInt32(int width, int height) : base(width, height)
        {}

        /// <summary>
        ///     Copies the value of the specified property object into the current property object.
        /// </summary>
        /// <param name="property">The property object from which to copy the value.</param>
        public void Copy(IProperty<SizeInt32> property)
        {
            var size = (SizeInt32)property;
            Set(size);
        }

        /// <summary>
        ///     Adds the specified values to the <see cref="Size{T}.Width" /> and <see cref="Size{T}.Height" /> dimensions.
        /// </summary>
        /// <param name="dx">The amount by which to change the horizontal dimension.</param>
        /// <param name="dy">The amount by which to change the vertical dimension.</param>
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "dy")]
        public void Add(int dx, int dy)
        {
            Set(Width + dx, Height + dy);
        }

        /// <summary>
        ///     Adds the specified values to the <see cref="Size{T}.Width" /> and <see cref="Size{T}.Height" /> dimensions.
        /// </summary>
        /// <param name="delta">A size containing the amounts by which to change the horizontal and vertical dimensions.</param>
        public void Add([NotNull] SizeInt32 delta)
        {
            delta.ValidateArgument("delta");
            Set(Width + delta.Width, Height + delta.Height);
        }

        /// <summary>
        ///     Subtracts the specified values to the <see cref="Size{T}.Width" /> and <see cref="Size{T}.Height" /> dimensions.
        /// </summary>
        /// <param name="dx">The amount by which to change the horizontal dimension.</param>
        /// <param name="dy">The amount by which to change the vertical dimension.</param>
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "dy")]
        public void Subtract(int dx, int dy)
        {
            Set(Width - dx, Height - dy);
        }

        /// <summary>
        ///     Subtracts the specified values to the <see cref="Size{T}.Width" /> and <see cref="Size{T}.Height" /> dimensions.
        /// </summary>
        /// <param name="delta">A size containing the amounts by which to change the horizontal and vertical dimensions.</param>
        public void Subtract([NotNull] SizeInt32 delta)
        {
            delta.ValidateArgument("delta");
            Set(Width - delta.Width, Height - delta.Height);
        }

        /// <summary>
        ///     Implements the add operator.
        /// </summary>
        /// <param name="left">The first operand.</param>
        /// <param name="right">The second operand.</param>
        /// <returns>The result of the operation.</returns>
        [SuppressMessage("Microsoft.Design", "CA1013:OverloadOperatorEqualsOnOverloadingAddAndSubtract")]
        public static SizeInt32 operator +([NotNull] SizeInt32 left, [NotNull] SizeInt32 right)
        {
            left.ValidateArgument("left");
            right.ValidateArgument("right");

            var result = left.Clone();
            result.Add(right);
            return result;
        }

        /// <summary>
        ///     Implements the subtract operator.
        /// </summary>
        /// <param name="left">The first operand.</param>
        /// <param name="right">The second operand.</param>
        /// <returns>The result of the operation.</returns>
        [SuppressMessage("Microsoft.Design", "CA1013:OverloadOperatorEqualsOnOverloadingAddAndSubtract")]
        public static SizeInt32 operator -([NotNull] SizeInt32 left, [NotNull] SizeInt32 right)
        {
            left.ValidateArgument("left");
            right.ValidateArgument("right");

            var result = left.Clone();
            result.Subtract(right);
            return result;
        }

        /// <summary>
        ///     Clones this instance.
        /// </summary>
        /// <returns>A new instance set to the same size as this instance.</returns>
        /// <remarks>The locking state is not copied</remarks>
        [NotNull]
        public SizeInt32 Clone()
        {
            return new SizeInt32(Width, Height);
        }
    }
}